load("@rules_java//java:defs.bzl", "java_plugin")
load("@rules_kotlin//kotlin:android.bzl", "kt_android_library")
load("@rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin", "kt_ksp_plugin")

kt_compiler_plugin(
    name = "serialization_plugin",
    compile_phase = True,
    id = "org.jetbrains.kotlin.serialization",
    stubs_phase = True,
    deps = [
        "@rules_kotlin//kotlin/compiler:kotlinx-serialization-compiler-plugin",
    ],
)

java_plugin(
    name = "autovalue",
    generates_api = 1,
    processor_class = "com.google.auto.value.processor.AutoValueProcessor",
    deps = ["@maven//:com_google_auto_value_auto_value"],
)

kt_ksp_plugin(
    name = "moshi-kotlin-codegen",
    processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider",
    deps = [
        "@maven//:com_squareup_moshi_moshi",
        "@maven//:com_squareup_moshi_moshi_kotlin",
        "@maven//:com_squareup_moshi_moshi_kotlin_codegen",
    ],
)

kt_android_library(
    name = "my_kt",
    srcs = glob(["src/main/java/**/*.kt"]),
    custom_package = "examples.android.lib",
    manifest = "src/main/AndroidManifest.xml",
    plugins = [
        ":moshi-kotlin-codegen",
        ":serialization_plugin",
        ":autovalue",
    ],
    resource_files = glob(["res/**"]),
    tags = ["trace"],
    visibility = ["//visibility:public"],
    deps = [
        ":res2",
        "@maven//:androidx_appcompat_appcompat",
        "@maven//:com_google_auto_value_auto_value_annotations",
        "@maven//:com_squareup_moshi_moshi",
        "@maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
    ],
)

android_library(
    name = "res2",
    custom_package = "examples.android.lib",
    manifest = "src/main/AndroidManifest.xml",
    resource_files = glob(["res2/**"]),
)
